package jee.boot.module.file.utils;

import com.github.pagehelper.util.StringUtil;
import org.apache.commons.lang3.StringUtils;

public class FileStoreConst {
    public static final String DEFAULT_FILE_TYPE_PNG = "png"; // 图片会生成预览
    public static final String DEFAULT_FILE_TYPE_JPG = "jpg"; // 图片会生成预览
    public static final String DEFAULT_FILE_TYPE_BMP = "bmp"; // 图片会生成预览
    public static final String DEFAULT_FILE_TYPE_GIF = "gif"; // 图片会生成预览
    public static final String DEFAULT_FILE_TYPE_PRE = "image/"; // 图片会生成预览
    public static final String DEFAULT_Y = "Y";
    public static final String DEFAULT_N = "N";
    public static final long DEFAULT_FILE_LEVEL = 1024L; // 文件大小处理基数
    public static final long DEFAULT_FILE_EXPIRE = 3153600000000L; // OSS文件过期时间(毫秒)
    public static final String WEBSERVICE_RET_SUCC_CODE = "0";
    public static final String SYMBOL_BLANK = "";

    public static final int MSG_BT_COMMON_006 = 20006; // 查询无数据
    public static final int MSG_BT_COMMON_007 = 20007; // 附件不存在
    public static final int MSG_BT_COMMON_008 = 20008; // 附件上传失败
    public static final int MSG_BT_COMMON_009 = 20009; // 附件下载失败
    public static final int MSG_BT_COMMON_010 = 20010; // 附件删除失败
    public static final int MSG_BT_COMMON_999 = 20999; // 系统异常，请联系管理员

    public static final String SYMBOL_SLASH = "/";
    public static final String SYMBOL_DASH = "-";
    public static final String SYMBOL_PRICK = ".";

    /**
     * 获取文件名后缀
     * @param filePathName
     * @return
     */
    public static String getSuffixFileName(String filePathName) {
        // 空判断
        if(StringUtil.isEmpty(filePathName)) {
            return filePathName;
        }

        // 返回后缀名
        String fullName = getFullFileName(filePathName);
        String SuffixFileName = fullName.substring(fullName.lastIndexOf(".") + 1, fullName.length());

        if(!StringUtils.isEmpty(SuffixFileName)) {
            return SuffixFileName;
        } else {
            return FileStoreConst.SYMBOL_BLANK;
        }
    }

    /**
     * 获取文件名后缀
     * @param filePathName
     * @return
     */
    public static String getFullFileName(String filePathName) {
        // 空判断
        if(StringUtil.isEmpty(filePathName)) {
            return filePathName;
        }

        // 返回后缀名
        String temp[] = filePathName.split("\\\\");
        return temp[temp.length-1];
    }
}
